package top.eggcode.component.query.clause;

import org.apache.commons.lang3.StringUtils;
import top.eggcode.component.query.def.LiteralSentence;

import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;

/**
 * Title:
 * Description: TODO
 * Date: 2021/9/2 13:27
 *
 * @author JiaQi Ding
 * @version 1.0
 */
public class SelectClause implements LiteralSentence {

    private final List<String> columns;

    public SelectClause() {
        columns = new LinkedList<>();
    }

    public SelectClause(List<String> columns) {
        this.columns = columns;
    }

    public SelectClause add(String columnName) {
        columns.add(columnName);
        return this;
    }

    public SelectClause add(String... columns) {
        this.columns.addAll(Arrays.asList(columns));
        return this;
    }

    public SelectClause add(List<String> columns) {
        this.columns.addAll(columns);
        return this;
    }


    @Override
    public String render() {

        StringBuilder selectClause = new StringBuilder("SELECT");
        selectClause.append(" ").append(StringUtils.join(this.columns, ", "));
        return selectClause.toString();
    }
}
